﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MeetingMinutesManager.Form;
using MeetingMinutesManager.Utils;

namespace MeetingMinutesManager.Maintenance
{
    public partial class TeamMaintenance : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            FormUtil.AuthenticateManager(Session, Response);
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            String team = txtTeam.Text.Trim();
            String parentTeam = ddlParents.SelectedValue.Trim();

            if (team.Equals(String.Empty) ||
                parentTeam.Equals(String.Empty))
            {
                Messenger.Show(Response, "Please fill all fields!");
                return;
            }

            try
            {
                TeamOperator.AddNewTeam(team, parentTeam);
            }
            catch (Exception ex)
            {
                Messenger.Show(Response, "Error: " + ex.Message);
                return;
            }

            Messenger.Show(Response, "Team added successfully!");

            grvTeams.DataBind();
            Clean();
        }

        protected void btnClean_Click(object sender, EventArgs e)
        {
            Clean();
        }

        private void Clean()
        {
            txtTeam.Text = String.Empty;
            ddlParents.ClearSelection();
        }
    }
}
